<template>
  <div class="Category">
    <el-card>
      <template #header>
        <div class="header">
          <span>销售额类别占比</span>
          <el-radio-group v-model="value">
            <el-radio-button label="全部渠道" />
            <el-radio-button label="线上" />
            <el-radio-button label="门店" />
          </el-radio-group>
        </div>
      </template>
      <div>
          <div ref="chart" class="chart" />
      </div>
    </el-card>
  </div>
</template>

<script>
import * as echarts from 'echarts'
export default {
  name: 'Category',
  data() {
    return {
      value: ''
    }
  },
  mounted() {
    const pieChart = echarts.init(this.$refs.chart)
    const option = {
      title:{
        text:'视频',
        subtext:'1204',
        left:'center',
        top:'center'
      },
      tooltip: {
        trigger: 'item'
      },
      series: [
        {
          name: 'Access From',
          type: 'pie',
          radius: ['40%', '70%'],
          avoidLabelOverlap: false,
          itemStyle: {
            borderColor: '#fff',
            borderWidth: 2
          },
          label: {
            show: true,
            position: 'outside'
          },
          labelLine: {
            show: true
          },
          data: [
            { value: 1048, name: '视频' },
            { value: 735, name: 'Direct' },
            { value: 580, name: 'Email' },
            { value: 484, name: 'Union Ads' },
            { value: 300, name: 'Video Ads' }
          ]
        }
      ]
    }
    pieChart.setOption(option)

    pieChart.on('mouseover',(params)=>{
      const {value,name} = params.data
      pieChart.setOption({
        title:{
          text:name,
          subtext:value,
        }
      })
    })
  }
}
</script>

<style lang="scss" scoped>
.Category {
  .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .chart {
    width: 100%;
    height: 350px;
  }
}
</style>
